package org.red_cross_service.controller;

import jakarta.servlet.http.HttpServletResponse;
import org.red_cross_service.common.anno.NoNeedToken;
import org.red_cross_service.common.response.Response;
import org.red_cross_service.domain.entity.SignEntity;
import org.red_cross_service.service.SignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/sign")
@CrossOrigin
public class SignController {

    @Autowired
    SignService signService;

    @NoNeedToken
    @PostMapping("/add")
    public Response addSign(@RequestBody SignEntity signEntity){
        return signService.addSign(signEntity);
    }

    @NoNeedToken
    @DeleteMapping("/delete")
    public Response deleteSign(Long signId){
        return signService.deleteSign(signId);
    }

    @NoNeedToken
    @PostMapping("/update")
    public Response updateSign(@RequestBody SignEntity signEntity){
        return signService.updateSign(signEntity);
    }

    @NoNeedToken
    @PostMapping("/list")
    public Response getSignList(@RequestBody SignEntity signEntity){
        return Response.success(signService.getSignList(signEntity));
    }

    //查询单条记录
    @NoNeedToken
    @PostMapping("/selectOne")
    public Response selectOne(@RequestBody SignEntity signEntity){
        return signService.selectOne(signEntity);
    }

    //查询用户正在进行的培训
    @NoNeedToken
    @GetMapping("/userTraining")
    public Response selectUserTraining(@RequestParam Integer userId){
        return signService.selectUserTraining(userId);
    }

    //根据用户id查询培训记录
    @NoNeedToken
    @GetMapping("/userList")
    public Response selectUserList(@RequestParam Integer userId,@RequestParam Integer type){
        return signService.selectUserList(userId,type);
    }

    @NoNeedToken
    @PostMapping("/export")
    public void exportSignList(HttpServletResponse response, @RequestBody SignEntity signEntity){
        signService.exportSignList(response,signEntity);
    }

}
